<template>
  <div style="text-align: center;" id="register">
    <!--  background-image: url('${require('@/assets/etty.jpg')}'引入照片-->
    <!--      <div class="box" :style="`position: relative; background-image: url('${require('@/assets/etty.jpg')}');`">-->

    <el-card
        :style="`width: 500px;height: 600px; margin: auto;background-image: url('${require('@/assets/etty.jpg')}');`">
      <div slot="header" style="font-size: 30px">欢迎来到lucky相册！</div>
      <el-form :model="user" :rules="rules" ref="loginForm" class="demo-ruleForm">
        <el-form-item label="姓名" prop="name">
          <el-input style="width: 400px" v-model="user.name"></el-input>
        </el-form-item>

          <el-form-item label="账号" prop="account" style="font-size: 18px">
            <el-input style="width: 400px" v-model="user.account"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input style="width: 400px" v-model="user.password"></el-input>

          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="tanchu">确定注册</el-button>
            <el-button @click="$router.push('/login')">去登录</el-button>
          </el-form-item>
      </el-form>
    </el-card>
  </div>

</template>

<script>

import axios from 'axios';

export default {
  name: "",
  data() {
    return {
      user: {},
      rules: {
        name: [
          {required: true, message: '请输入姓名', trigger: 'blur'}
        ],

        account: [
          {required: true, message: '请输入账号', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 1, max: 32, message: '长度在 1 到 32 个字符', trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    tanchu(){
      confirm("注册成功！")
    },
    register() {
      this.$refs.loginForm.validate((r) => {
        if (r) {
          axios.post('http://localhost:8090/api/user/register', this.user).then(res => {
            alert(res.data.msg);
            if (res.data.status === 1) {
              localStorage.setItem('TOKEN', res.data.data.token);
              this.$router.push('/index');
            }
            console.log(res);
          })
        } else {
          this.$message.warning('请填完信息后再登录');
        }
      })
    }
  }
}

</script>

<style lang="scss">
#register {
.el-card__body {
  padding: 55px;
}

.el-card__header {
  padding: 17px 20px;
  border-bottom: 1px solid #EBEEF5;
  box-sizing: border-box;
}
  .el-input__inner {
    opacity: 0.8 !important;
  }
}
.label{
  font-size: 18px;
}
</style>